<template>
  <div>
    <h1>
      当前的值：{{ count }}  {{oddOrEven}}
    </h1>
    <select v-model="val">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
      <option :value="4">4</option>
    </select>
    <button @click="handleIncrement">+</button>
    <button @click="handleDecrement">-</button>
    <button @click="handleIfOddIncrement">如果是奇数就加</button>
    <button @click="handleIncrementAsync">延迟1s加</button>
    
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions,  mapMutations } from "vuex";

export default {
  name: "App",
  data(){
    return {
       val: 1,
    }
  },
  methods:{
    ...mapActions("counter",["increment","decrement","ifOddIncrement","incrementAsync"]),
    ...mapMutations("counter",["INCREMENT","DECREMENT","IFODDINCREMENT","INCREMENTASYNC"]),
    handleIncrement(){
       this.increment(this.val);
    },
    handleDecrement(){
        this.decrement(this.val);
    },
    handleIfOddIncrement(){
       this.ifOddIncrement(this.val);
    },
    handleIncrementAsync(){
       this.incrementAsync(this.val);
    }
  },
  computed: {
    ...mapState("counter", ["count"]),
    ...mapGetters("counter", ["oddOrEven"]),
  },
};

</script>

